package com.imut.oa.controller.user;

import com.imut.oa.common.BaseResponse;
import com.imut.oa.common.ResultUtils;
import com.imut.oa.util.ThreadLoaclUtil;
import com.imut.oa.pojo.dto.EmployeeAttendanceDTO;
import com.imut.oa.pojo.dto.WorkTimeConfigDTO;
import com.imut.oa.pojo.vo.AttendanceRecordVO;
import com.imut.oa.service.AttendanceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
    @RequestMapping("/user/attendance")
@Slf4j
@Tag(name = "用户打卡")
public class UserAttendanceController {
    @Autowired
    private AttendanceService attendanceService;

    /**
     * 打卡
     * @param employeeAttendanceDTO
     * @return
     */
    @PostMapping
    @Operation(summary = "打卡")
    public BaseResponse attendance(@RequestBody EmployeeAttendanceDTO employeeAttendanceDTO){
        log.info("打卡信息：{}",employeeAttendanceDTO);
        attendanceService.attendance(employeeAttendanceDTO);
        return ResultUtils.success();
    }
    /**
     * 获取打卡记录
     */
    @PostMapping("/record")
    @Operation(summary = "获取打卡记录")
    public BaseResponse<List<AttendanceRecordVO>> record(){
        Long currentId = ThreadLoaclUtil.getCurrentId();
        log.info("获取当前登录用户信息：{}",currentId);
        List<AttendanceRecordVO> records = attendanceService.getTodayRecords(currentId);
        return ResultUtils.success(records);
    }

    @GetMapping("/worktimeconfig")
    @Operation(summary = "获取上班时间和下班时间的配置")
    public BaseResponse<WorkTimeConfigDTO> getWorkTimeConfig() {
        log.info("获取上班时间和下班时间的配置");
        WorkTimeConfigDTO config = attendanceService.getWorkTimeConfig();
        return ResultUtils.success(config);
    }
    /**
     * 分页获取考勤记录
     * @param page 页码
     * @param pageSize 每页记录数
     * @return 考勤记录列表
     */
    @GetMapping("/records")
    @Operation(summary = "分页获取考勤记录")
    public BaseResponse<List<AttendanceRecordVO>> getAttendanceRecords(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize) {
        Long currentId = ThreadLoaclUtil.getCurrentId();
        log.info("获取当前登录用户信息：{}，分页信息：page={}，pageSize={}", currentId, page, pageSize);
        List<AttendanceRecordVO> records = attendanceService.getAttendanceRecords(currentId, page, pageSize);
        return ResultUtils.success(records);
    }
}
